home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-28 | 2.2 KB | 71 lines | [TEXT/CWIE] |
- // Array.h
-
- #ifndef Array_h
- #define Array_h
-
- #ifndef ArrayOf_h
- #include "ArrayOf.h"
- #endif
-
- template < class Element, uint32 size >
- class Array
- {
- typedef ArrayOf<Element> ArrayType;
- typedef ConstArrayOf<Element> ConstArrayType;
-
- private:
- const ArrayType head;
- struct
- {
- Element elements[ size ];
- } body;
-
- public:
- Array()
- : head( body.elements, size )
- {}
-
- operator const ArrayOf<Element>&() { return head; }
- operator const ConstArrayOf<Element>&() const { return head; }
-
- void operator=( const Array<Element, size>& r ) { body = r.body; }
-
- Element& operator[]( uint32 i )
- { Assert( i < size ); return body.elements[ i ]; }
-
- const Element& operator[]( uint32 i ) const
- { Assert( i < size ); return body.elements[ i ]; }
-
- uint32 Length() const { return size; }
- URange32 Range() const { return URange32( 0, Length() ); }
-
- uint32 BoundedLength( uint32 bound ) const
- { return ( size <= bound ) ? size : bound; }
-
- bool IsEmpty() const { return size == 0; }
-
- // These operators express the containment ordering
- bool operator==( ConstArrayType r ) const { return head == r; }
- bool operator!=( ConstArrayType r ) const { return head != r; }
- bool operator>=( ConstArrayType r ) const { return head >= r; }
- bool operator>( ConstArrayType r ) const { return head > r; }
-
- Element *Start() { return body.elements; }
- Element *End() { return body.elements+size; }
- const Element *Start() const { return body.elements; }
- const Element *End() const { return body.elements + size; }
-
- ArrayType Head( uint32 position ) { return head.Head( position ); }
- ArrayType Tail( uint32 position ) { return head.Tail( position ); }
- ArrayType Middle( URange32 range ) { return head.Middle( range ); }
-
- ConstArrayType Head( uint32 position ) const { return head.Head( position ); }
- ConstArrayType Tail( uint32 position ) const { return head.Tail( position ); }
- ConstArrayType Middle( URange32 range ) const { return head.Middle( range ); }
-
- uint32 operator<<( ConstArrayType r ) { return head << r; }
- uint32 BitwiseCopy( ConstArrayType r ) { return head.BitwiseCopy( r ); }
- };
-
- #endif
-